home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / Examples / Text / Textension / Include / Streams.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-21  |  3.6 KB  |  126 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        Streams.h
  3.  
  4.     Contains:    xxx put contents here xxx
  5.  
  6.     Written by:    Essam Zaky
  7.  
  8.     Copyright:    © 1994 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <2>      1/4/94    EZ        clean up
  13.          <1>      1/4/94    EZ        first checked in
  14.  
  15. */
  16.  
  17. #ifndef _Streams_
  18. #define _Streams_
  19.  
  20. #ifndef _ToolBoxDump_
  21. #include "ToolBoxDump.h"
  22. #endif
  23.  
  24. #ifndef _TextensionCommon_
  25. #include "TextensionCommon.h"
  26. #endif
  27.  
  28. #ifndef _Array_
  29. #include "Array.h"
  30. #endif
  31. //***************************************************************************************************
  32.  
  33. class    CStream    :    public HandleObject {
  34. public:
  35.     CStream();
  36.     
  37.     void IStream();
  38.     virtual void Free();
  39.     
  40.     virtual OSErr WriteBytes(const void* theBytes, long bytesCount) = 0;
  41.     virtual OSErr ReadBytes(void* theBytes, long bytesCount) = 0;
  42.     
  43.     inline OSErr WriteChar(char theChar) {return this->WriteBytes(&theChar, sizeof(theChar));}
  44.     inline OSErr WriteBoolean(Boolean theBoolean) {return this->WriteBytes(&theBoolean, sizeof(theBoolean));}
  45.     inline OSErr WriteShort(short theShort) {return this->WriteBytes(&theShort, sizeof(theShort));}
  46.     inline OSErr WriteLong(long theLong) {return this->WriteBytes(&theLong, sizeof(theLong));}
  47.     inline OSErr WritePoint(Point thePoint) {return this->WriteBytes(&thePoint, sizeof(thePoint));}
  48.     inline OSErr WriteRect(const Rect* theRect) {return this->WriteBytes(theRect, sizeof(Rect));}
  49.     
  50.     #ifdef txtnNever
  51.     OSErr WriteHandle(Handle theHandle);
  52.     //writes the handleSize then handlebytes
  53.     #endif
  54.     
  55.     inline OSErr ReadChar(char* theChar) {return this->ReadBytes(theChar, sizeof(char));}
  56.     inline OSErr ReadBoolean(Boolean* theBoolean) {return this->ReadBytes(theBoolean, sizeof(Boolean));}
  57.     inline OSErr ReadShort(short* theShort) {return this->ReadBytes(theShort, sizeof(short));}
  58.     inline OSErr ReadLong(long* theLong) {return this->ReadBytes(theLong, sizeof(long));}
  59.     inline OSErr ReadPoint(Point* thePoint) {return this->ReadBytes(thePoint, sizeof(Point));}
  60.     inline OSErr ReadRect(Rect* theRect) {return this->ReadBytes(theRect, sizeof(Rect));}
  61.     
  62.     #ifdef txtnNever
  63.     OSErr ReadHandle(Handle* theHandle);
  64.     //creates a new handle Reads the handleSize then handlebytes
  65.     #endif
  66.     
  67.     virtual long GetPosition() const;
  68.     virtual void SetPosition(long newPosition);
  69.     virtual void Skip(long count);
  70.     
  71.     virtual long GetSize() const = 0;
  72.     
  73.     virtual OSErr Append(long count) = 0;
  74.     //Appends "count" bytes at the end of the stream, position is not changed
  75.     
  76.     virtual void Empty();
  77.     
  78.     virtual OSErr Load(long size, Ptr* data) = 0; //fPosition is advanced by "size"
  79.     virtual void Unload(Ptr data) = 0; //should be called even if "Load" returns an error
  80.     
  81. protected:
  82.     long fPosition;
  83.  
  84. private:
  85. };
  86. //***************************************************************************************************
  87.  
  88. /*CHandleStream could be declared as  public CStream, public CArray, but can't have multiple inheritance!*/
  89.  
  90. class    CHandleStream    :    public CStream {
  91. public:
  92.     CHandleStream();
  93.     
  94.     void IHandleStream();
  95.     
  96.     //•override
  97.     virtual void Free();
  98.     
  99.     virtual OSErr WriteBytes(const void* theBytes, long bytesCount);
  100.     virtual OSErr ReadBytes(void* theBytes, long bytesCount);
  101.     
  102.     virtual long GetSize() const;
  103.     
  104.     virtual OSErr Append(long count);
  105.     
  106.     virtual void Empty();
  107.  
  108.     virtual OSErr Load(long size, Ptr* data);
  109.     virtual void Unload(Ptr data);
  110.  
  111.     //•own
  112.     
  113.     inline Ptr GetStreamPtr() {return Ptr(fArray->GetElementPtr(0));}
  114.     
  115.     inline void* LockStream(Boolean moveHi = false) {return fArray->LockArray(moveHi);}
  116.     inline void UnlockStream() {fArray->UnlockArray();}
  117.     
  118. protected:
  119.  
  120. private:
  121.     CArray* fArray;
  122. };
  123. //***************************************************************************************************
  124.  
  125. #endif
  126.